package com.dongly.selection;

import com.dongly.Sort;
import com.dongly.SortTestHelper;
import com.dongly.Student;

import java.util.Arrays;

public class SortComparableTest implements Sort<Integer> {

    @Override
    public void sort(Integer[] integers) {
        int length = integers.length;
        int minIndex;
        Integer temp;
        for (int i = 0; i < length; i++) {
            minIndex = i;
            for (int j = i + 1; j < length; j++) {
                if (integers[j].compareTo(integers[minIndex]) < 0) {
                    minIndex = j;
                }
            }
            temp = integers[i];
            integers[i] = integers[minIndex];
            integers[minIndex] = temp;
        }
    }

    public static void main(String[] args) {
        Integer[] array = SortTestHelper.generateRandomArray(10, 1, 10);
        System.out.println(Arrays.toString(array));
        SortTestHelper.testSort(new SortComparableTest(), array);

        System.out.println(Arrays.toString(array));
    }
}
